Fix MageCookies.getAll() throwing on non-JSON cookies (e.g. Adobe s_sq)#2
Open
Maksold wants to merge 1 commit into
Open
Fix MageCookies.getAll() throwing on non-JSON cookies (e.g. Adobe s_sq)#2Maksold wants to merge 1 commit into
Maksold wants to merge 1 commit into
Conversation
JSON.parse() ran on any cookie starting with [ or {, so a foreign
cookie that only looks like JSON (e.g. Adobe Analytics s_sq="[[B]]")
threw a SyntaxError and aborted every caller of getAll()/get().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MageCookies.getAll()runsJSON.parse()on any cookie whose value starts with[or{, unguarded. A value that looks like JSON but isn't throws aSyntaxError.Real-world trigger: Adobe Analytics' ActivityMap cookie
s_sq, whose empty-state value is[[B]].getAll()throws before returning any key, so every consumer dies at once —get('form_key')inajax-queue.phtmlandpolling.phtml, plusmage-messagesandsection_data_ids. Net effect: the whole AJAX layer (grid search/sort/filter, form save, polling) silently stops for that visitor, on frontend and adminhtml alike.Fix: wrap the parse in try/catch and fall back to the raw string. JSON cookies Loki set still round-trip; foreign cookies no longer abort the request.
Repro:
document.cookie = 's_sq=%5B%5BB%5D%5D', open any Loki grid, sort →Uncaught SyntaxError: "[[B]]" is not valid JSON.FYI:
[[B]]iss_sq's documented null value (ActivityMap withtrackInlineStats=false) — ref.